package com.xbongbong.rule.symbol;

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.PaasDateUtil;
import com.xbongbong.rule.symbol.base.AbstractSymbol;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * 动态值校验
 * 字段类型：各种日期
 *
 * @author LiZhikang
 * @date 2023/4/20 16:27
 */
@Slf4j
public class DynamicSymbol extends AbstractSymbol {
    @Override
    public boolean operation() {
        Long beginTime;
        Long endTime;
        Long realValue;
        try {
            List<Object> timeList = PaasDateUtil.computeTime(conditionValueList);
            beginTime = Long.valueOf(timeList.get(0).toString());
            endTime = Long.valueOf(timeList.get(1).toString());
            realValue = Long.valueOf(value.toString());
        } catch (XbbException e) {
            log.error("Compute time fail", e);
            return false;
        }
        if (realValue >= beginTime && realValue < endTime){
            return true;
        }
        return false;
    }
}
